.text
.globl goto_co, save_co
# int goto_co(CoContext*)
goto_co:
    mov 0(%rdi), %rsp   # reload context
    mov 8(%rdi), %rbp
    mov 24(%rdi), %rbx
    mov 32(%rdi), %r12
    mov 40(%rdi), %r13
    mov 48(%rdi), %r14
    mov 56(%rdi), %r15

    mov 16(%rdi), %rdx   # push pc
    mov %rdx, 0(%rsp)
    
    mov $1, %rax        # return 1
    
    ret                 # after ret, the pc_reg's value will be pop and load

# int save_co(CoContext*)
save_co:
    lea 8(%rsp), %rdx
    mov %rdx, 0(%rdi)   # save context
    mov %rbp, 8(%rdi)
    mov %rbx, 24(%rdi)
    mov %r12, 32(%rdi)
    mov %r13, 40(%rdi)
    mov %r14, 48(%rdi)
    mov %r15, 56(%rdi)

    mov (%rsp), %rdx   # save pc
    mov %rdx, 16(%rdi)

    mov $0, %rax        # return 0
    ret
